'''
Created on Aug 25, 2011

@author: david
'''

from pspy.gae.actiondomain import PspyAction

class Email(PspyAction):
    """
    Default Action 
    spawns index.gen
    """
    def execute(self): 
        from app.Ranger.agents import AccessAgent
        from pspy import Notification
        import json
        
        # prelims
        req = self.request
        rslts = {'results':200,'message':"Ok"}
        ema = req.getParameter("ema")
        
        try:
            # send email 
            AccessAgent().sendReset(ema)
            
            rslts["message"] = "Please check your email, we just sent instructions to complete the reset of your passwords"
        
        except Exception as ex:
            # report back error
            Notification(str(ex)).setException(ex)
            rslts = {'results':500,'message':str(ex)}
        
        # send back results
        return self.JSONOutput(json.dumps(rslts))
    
    
    def sess_check(self):
        return True